package com.ruoyi.web.controller.mobile;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mobile.domain.TakeMedicineRecord;
import com.ruoyi.mobile.service.ITakeMedicineRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用药打卡记录Controller
 * 
 * @author ruoyi
 * @date 2022-09-20
 */
@RestController
@RequestMapping("/mobile/takemedicine")
public class TakeMedicineRecordController extends BaseController
{
    @Autowired
    private ITakeMedicineRecordService takeMedicineRecordService;

    /**
     * 查询用药打卡记录列表
     */
    @PreAuthorize("@ss.hasPermi('mobile:takemedicine:list')")
    @GetMapping("/list")
    public TableDataInfo list(TakeMedicineRecord takeMedicineRecord)
    {
        startPage();
        List<TakeMedicineRecord> list = takeMedicineRecordService.selectTakeMedicineRecordList(takeMedicineRecord);
        return getDataTable(list);
    }

    /**
     * 导出用药打卡记录列表
     */
    @PreAuthorize("@ss.hasPermi('mobile:takemedicine:export')")
    @Log(title = "用药打卡记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TakeMedicineRecord takeMedicineRecord)
    {
        List<TakeMedicineRecord> list = takeMedicineRecordService.selectTakeMedicineRecordList(takeMedicineRecord);
        ExcelUtil<TakeMedicineRecord> util = new ExcelUtil<TakeMedicineRecord>(TakeMedicineRecord.class);
        util.exportExcel(response, list, "用药打卡记录数据");
    }

    /**
     * 获取用药打卡记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('mobile:takemedicine:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(takeMedicineRecordService.selectTakeMedicineRecordById(id));
    }

    /**
     * 新增用药打卡记录
     */
    @PreAuthorize("@ss.hasPermi('mobile:takemedicine:add')")
    @Log(title = "用药打卡记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TakeMedicineRecord takeMedicineRecord)
    {
        return toAjax(takeMedicineRecordService.insertTakeMedicineRecord(takeMedicineRecord));
    }

    /**
     * 修改用药打卡记录
     */
    @PreAuthorize("@ss.hasPermi('mobile:takemedicine:edit')")
    @Log(title = "用药打卡记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TakeMedicineRecord takeMedicineRecord)
    {
        return toAjax(takeMedicineRecordService.updateTakeMedicineRecord(takeMedicineRecord));
    }

    /**
     * 删除用药打卡记录
     */
    @PreAuthorize("@ss.hasPermi('mobile:takemedicine:remove')")
    @Log(title = "用药打卡记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(takeMedicineRecordService.deleteTakeMedicineRecordByIds(ids));
    }
}
